<?php
/**
 * Users controller class
 */
class Member_UserController extends Zend_Controller_Action
{
	/**
	 * Display login page
	 */
	public function loginAction()
	{
		$loginForm = new Member_Form_UserLogin();
		$this->view->loginForm = $loginForm;
		
		$identity = Member_Service_User::getIdentity();
		if( !isset($identity->username)  ){
			$service = new Member_Service_User();
			if ($this->getRequest()->isPost()) {
				$service = new Member_Service_User();
				$result = $service->login($this->getRequest()->getPost());
				if ($result) {
					$this->_helper->redirector('profile');
				}
			}
		}
		else {
			$this->_helper->redirector('profile');
		}
	}

	/**
	 * Kill the user's session
	 */
	public function logoutAction()
	{
		$service = new Member_Service_User();
		$service->logout();

		$this->_helper->redirector('login');
	}

	/**
	 * Display profil page
	 */
	public function profileAction()
	{
		$this->view->identity = Member_Service_User::getIdentity();
	}
}
